package com.da.javatest.niuke.baodian;

import java.util.Arrays;

/**
 * @author chenlida
 * @date 2020/10/12 15:55
 * https://www.nowcoder.com/practice/845ec89145b04b2b855d020d9c3ea2ef?tpId=8&tags=&title=&diffculty=0&judgeStatus=0&rp=1
 */
public class C61Exchange {
    /**
     * x+y=xx
     * x-y=xxx
     */
    public static int[] exchangeAB(int[] AB) {
        AB[0] = AB[0] + AB[1];
        AB[1] = AB[0] - 2 * AB[1];
        AB[0] = (AB[0] - AB[1]) / 2;
        AB[1] = AB[0] + AB[1];
        return AB;
    }

    public static int[] exchangeAB2(int[] AB) {
        AB[0] = AB[0] ^ AB[1];
        AB[1] = AB[0] ^ AB[1];
        AB[0] = AB[0] ^ AB[1];
        return AB;
    }

    public static void main(String[] args) {
        System.out.println(Arrays.toString(exchangeAB(new int[] {1, 2})));
        System.out.println(Arrays.toString(exchangeAB2(new int[] {22, 33})));
    }
}
